 <?php
 session_start();
 include_once ("Login/databaseconnection.php");
 $current_table="deleted_teacher";
 date_default_timezone_set("Europe/Paris");
  	$t_d=date("Y/m/d");
   $T_NIC_Number=$_GET['T_NIC_Number'];
   $sqlre=mysql_query("SELECT * FROM deleted_teacher WHERE T_NIC_Number='$T_NIC_Number'");
	if(mysql_num_rows($sqlre)!=0)
	{
	$Role=$_POST['Role'];
	$T_NIC_Number=$_POST['T_NIC_Number'];
	$School_Id=$_POST['School_Id'];
	$First_Name=$_POST['First_Name'];
	$Last_Name=$_POST['Last_Name'];
	$Date_Of_Birth=$_POST['Date_Of_Birth'];
	$Gender=$_POST['Gender'];
	$Nature_Of_Appointment=$_POST['Nature_Of_Appointment'];
	$Service=$_POST['Service'];
	$Academic_Qualifications=$_POST['Academic_Qualifications'];
    $Professional_Qualifications=$_POST['Professional_Qualifications'];
	$Achieve=$_POST['Achievements_Awards'];
	$Address=$_POST['Address'];
	$Mobile_Tp_Number=$_POST['Mobile_Tp_Number'];
	$Home_Tp_Number=$_POST['Home_Tp_Number'];
	$Office_Tp_Number=$_POST['Office_Tp_Number'];
	$Appointment_Date=$_POST['Appointment_Date'];
	$Appointed_Subject=$_POST['Appointed_Subject'];
    $Last_Updated_Date=$_POST['Last_Updated_Date'];
	$Accessed_By=$_POST['Accessed_By'];
		$_SESSION['Accessed_By']=$Accessed_By;
	
	$sql=mysql_query("INSERT INTO teacher(Role,T_NIC_Number,School_Id,First_Name,Last_Name,Date_Of_Birth,Gender,Nature_Of_Appointment,Academic_Qualifications,Professional_Qualifications,Achievements_Awards,Service,Address,Mobile_Tp_Number,Home_Tp_Number,Office_Tp_Number,Appointment_Date,Appointed_Subject,Last_Updated_Date)VALUES('$Role','$T_NIC_Number','$School_Id','$First_Name','$Last_Name','$Date_Of_Birth','$Gender','$Nature_Of_Appointment','$A_Qua','$Profe_Qualifications','$Achieve','$Service','$Address','$Mobile_Tp_Number','$Home_Tp_Number','$Office_Tp_Number','$Appointment_Date','$Appointed_Subject','$t_d')");
if($sql)
{ 
if($row=mysql_fetch_array($sqlre))
	{
	$Tra_Id=$row[''];
	$Dura=$row['Duration'];
	$Mem_Id=$row['Member_Id'];
	$Fr_Date=$row['From_Date'];
	
	$Training_Id=explode(",",$Tra_Id);
	$Duration=explode(",",$Dura);
	$Member_Id=explode(",",$Mem_Id);
	$From_Date=explode(",",$Fr_Date);
	
	for($i=0;$i<count($Training_Id);$i++)
	{
	mysql_query("INSERT INTO training_details(Training_Id,Teacher_NIC,Duration,Last_Updated_Date) VALUES('$Training_Id[$i]','$Teacher_NIC','$Duration[$i]','$t_d')");
	mysql_query("INSERT INTO  resource_team(Training_Id,T_NIC_Number,Member_Id,From_Date,Last_Updated_Date)VALUES('$Training_Id[$i]','$T_NIC_Number','$Member_Id','$From_Date[$i]','$t_d')");
  }
}
	$resultdel=mysql_query("DELETE FROM deleted_teacher WHERE T_NIC_Number='$T_NIC_Number'");
if(!$resultdel)
{
	 $_SESSION['error']="but this record is not removed from the recycle bin!";
}
$_SESSION['error']="Successfully restored!";
}
   if(!$sql)
{
	 $_SESSION['error']="Sorry,an error occured  please try again!";
}	
}
?>
